package com.ple.app.jzsf;

import android.support.v4.view.ViewPager;
import android.widget.ImageButton;

import java.util.List;

/**
 * Created by twenj on 2016/11/10.
 */

public class TabChangeListener implements ViewPager.OnPageChangeListener  {

    private ViewPager viewPager;
    private List<ImageButton> imgBtnList;
    TabChangeListener(ViewPager viewPager,List<ImageButton> imgBtnList){
        this.viewPager = viewPager;
        this.imgBtnList = imgBtnList;
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        resetImage();
        int currentItem = viewPager.getCurrentItem();
        switch (currentItem){
            case 0:
                imgBtnList.get(0).setImageResource(R.mipmap.ic_launcher_white);
                break;
            case 1:
                imgBtnList.get(1).setImageResource(R.mipmap.ic_launcher_white);
                break;
            case 2:
                imgBtnList.get(2).setImageResource(R.mipmap.ic_launcher_white);
                break;
            case 3:
                imgBtnList.get(3).setImageResource(R.mipmap.ic_launcher_white);
                break;
            case 4:
                imgBtnList.get(4).setImageResource(R.mipmap.ic_launcher_white);
                break;
            default:
                break;

        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    /**
     * 将所有的图片设置为默认色
     */
    private void resetImage() {
        for(ImageButton igb:imgBtnList){
            igb.setImageResource(R.mipmap.ic_launcher);
        }
    }
}
